# -*- coding: utf-8 -*-

from django.shortcuts import render
from django.views.decorators import csrf
from .forms import AddForm
from django.http import HttpResponse


# 接收POST请求数据
def search_post(request):
    ctx = {}
    if request.POST:
        ctx['rlt'] = request.POST['q']
    return render(request, "post.html", ctx)

def save_file(file):
    with open('file', 'wb') as fp:
        for chunk in file.chunks():
            fp.write(chunk)

def index(request):
    if request.method == 'GET':
        form = MyForm()
        return render(request, 'add.html', {'form':form})
    else:
        myfile = request.FILES.get('myfile')
        save_file(myfile)
        return HttpResponse('succcess')
